<?php
/**
 *  普通订单支付明细
*/

namespace app\api\model;


use think\facade\Lang;

class OrderPayment extends BaseModel
{

    protected $append = ['status_text'];
    protected $attributes = [
        'pay_type' => [
            '00' => 'payType.collection',  // 收款
            '01' => 'payType.refundDeposit',  // 退押金
            '02' => 'payType.refund'  // 退款
        ],
        'pay_status' => [
            '00' => 'paymentStatus.inReview',            // 审核中
            '01' => 'paymentStatus.paymentSuccessful',  // 支付成功
            '02' => 'paymentStatus.paymentFailed',       // 支付失败
            '03' => 'paymentStatus.pendingPayment'       // 待支付
        ],
    ];

    /**
     *  图片
    */
    public function images()
    {
        return $this->hasOne(Images::class, 'id', 'transfer_voucher_id');
    }

    /**
     *  价格
     */
    public function getPayAmountAttr($value)
    {
        if (is_null($value)){
            return '';
        } else {
            return $value;
        }
    }

    /**
     *  支付状态
     */
    public function getStatusTextAttr($value,$data)
    {


        $statusList = $this->attributes;
    
        // 检查 status 是否存在
        if (!isset($data['status'])) {
            return Lang::get('paymentStatus.statusError');
        }
        
        if (isset($statusList['pay_status'][$data['status']])) {
            return Lang::get($statusList['pay_status'][$data['status']]);
        }
        
        return Lang::get('paymentStatus.statusError');
    }

    /**
     *  支付状态
     */
    public function getPayTypeAttr($value,$data)
    {


        $statusList = $this->attributes;
        if (isset($statusList['pay_status'][$data['status']])){
            return Lang::get($statusList['pay_status'][$data['status']]);
        } else {
            return Lang::get('paymentStatus.statusError');
        }
    }

    /**
     *  过去订单状态
     */
    public function getFieldEnum($field)
    {
        if ('ALL' === strtoupper($field)) {
            return [
                'pay_type' => $this->attributes['pay_type'],
                'pay_status' => $this->attributes['pay_status'],
            ];
        } else {
            return [$field => $this->$field];
        }
    }

}
